<?php
class TopPages extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$data = array ();
		$term = rqst ( 'term' );
		$term = trim ( $term );
		if (! empty ( $term )) {
			$pM = new WebPageModel ();
			$where ['status'] = 'published';
			$lary ['title LIKE'] = "%$term%";
			$lary ['OR'] = array ('subtitle LIKE' => "%$term%" );
			$lary ['OR'] = array ('source LIKE' => "%$term%" );
			$lary ['OR'] = array ('author LIKE' => "%$term%" );
			if (is_numeric ( $term )) {
				$lary ['OR'] = array ('page_id' => intval ( $term ) );
			}
			$where ['AND'] = $lary;
			$data = $pM->where ( $where )->limit ( 15 )->sortDesc ( 'publish_time' )->retrieve ( 'page_id as id,title as label' );
			$data = $data ? $data->toArray () : array ();
		}
		return new JsonView ( $data );
	}
}